www.gusucode.com > 24Beta 虚拟主机版 1.0.0 Beta源码程序 > 24Beta 虚拟主机版 1.0.0 Beta源码程序/24Beta-1.0.0-vhost/protected/models/Topic.php
<?php class Topic extends CActiveRecord { /** * The followings are the available columns in table 'Topic': * @var integer $id * @var string $name * @var string $icon * @var integer $article_nums * @var string $remark * @var integer $order_id * @var integer $create_time * @var string $create_ip * @var string $create_user */ /** * Returns the static model of the specified AR class. * @return CActiveRecord the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } /** * @return string the associated database table name */ public function tableName() { return 'Topic'; } /** * @return array validation rules for model attributes. */ public function rules() { return array( array('name','length','max'=>50), array('icon','length','max'=>50), array('remark','length','max'=>50), array('create_ip','length','max'=>15), array('create_user','length','max'=>30), array('post_nums, order_id, create_time', 'numerical', 'integerOnly'=>true), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'maxVisitPosts' => array(self::HAS_MANY, 'Post', 'topic_id', 'order' => 'visit_nums desc', 'limit' => param('relativePostsNums')), 'maxCommentsPosts' => array(self::HAS_MANY, 'Post', 'topic_id', 'order' => 'comment_nums desc', 'limit' => param('relativePostsNums')), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id'=>'Id', 'name'=>'Name', 'icon'=>'Icon', 'article_nums'=>'Article Nums', 'remark'=>'Remark', 'order_id'=>'Order', 'create_time'=>'Create Time', 'create_ip'=>'Create Ip', 'create_user'=>'Create User', ); } public function getActiveTopics($nums = null) { $criteria = $this->getDbCriteria(); if ($nums !== null ) $criteria->limit = $nums; $criteria->order = 'order_id asc, post_nums desc, id asc'; $criteria->condition = 'isvalid = :isvalid'; $criteria->params = array('isvalid' => 1); $data = $this->findAll($criteria); return $data; } public function getIdNamePairs() { $topics = $this->getActiveTopics(); if (empty($topics)) return array(); foreach ($topics as $v) { $data[$v->id] = $v->name; } asort($data); return $data; } public function getTopicIcon() { return param('uploadBaseUrl') . $this->icon; } }